package edu.sctu.lab03;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author:Mrzhang
 * @Description:
 * @Date:2018.05.15 17:20
 **/
public class TestServlet extends HttpServlet{

    /**
     * 继承HttpServlet后，这个类就是一个Servlet
     */

    //重写doGet方法
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        DataBase dataBase=new DataBase();
        List<User> userList= new ArrayList<>();
        try {
            userList = dataBase.getUserList();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        req.setAttribute("userList",userList);

        //连接Jsp和Servlet
        req.getRequestDispatcher("/userList.jsp").forward(req,resp);
    }
}
